package com.hailiang.study.javase.java.util.stream;

import com.hailiang.study.javase.java.util.stream.vo.Student;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Collectors_groupingBy {

    /**
     * 多级分组
     *      先按性别分组，然后按是否及格分组
     */
    @Test
    public void testMultiGroupBy() {
        List<Student> students = Arrays.asList(
                new Student(1, 19, "张三", "M", true),
                new Student(1, 18, "李四", "M", false),
                new Student(1, 21, "王五", "F", true),
                new Student(1, 20, "赵六", "F", false)
        );

        Map<String, Map<Boolean, List<Student>>> result = students.stream().collect(Collectors.groupingBy(Student::getSex, Collectors.groupingBy(Student::isPass)));
        System.out.println(result);
    }

}
